package ${package.ServiceImpl};

import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import java.math.BigDecimal;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.puruo.mindhall.utils.SnowflakeIdWorker;
import java.util.List;
import com.puruo.mindhall.bean.PageInfo;

@Service
public class ${table.serviceImplName} implements ${table.serviceName} {

	@Autowired
	private ${table.mapperName} ${table.entityPath}Mapper;


	/**
	*  查询表${table.name}所有信息
	*/
	@Override
	public List<${entity}> findAll() {
 		List<${entity}> list = ${table.entityPath}Mapper.findAll();
		return list;
	}

<#list table.fields as field>
<#if field.keyFlag>
	/**
	*  条件查询表${table.name}信息
	*/
	@Override
	public List<${entity}> getByEntity(${entity} ${table.entityPath}) {
		List<${entity}> list  = ${table.entityPath}Mapper.getByCondition(${table.entityPath});
		return list;
	}
</#if>
</#list>

<#list table.fields as field>
<#if field.keyFlag>
	/**
	*  查询表${table.name}信息
	*/
	@Override
	public ${entity} getById(<#if field.propertyType == "BigDecimal">Long</#if><#if field.propertyType != "BigDecimal">${field.propertyType}</#if> ${field.propertyName}) {
		${entity} entity = ${table.entityPath}Mapper.getById(${field.propertyName});
		return entity;
	}
</#if>
</#list>

<#list table.fields as field>
<#if field.keyFlag>
	/**
	* 删除表${table.name}信息
	*/
	@Override
	public int deleteById(<#if field.propertyType == "BigDecimal">Long</#if><#if field.propertyType != "BigDecimal">${field.propertyType}</#if> ${field.propertyName}) {
        int rc =${table.entityPath}Mapper.deleteById(${field.propertyName});
		return rc;
	 }
</#if>
</#list>

<#list table.fields as field>
<#if field.keyFlag>
	/**
	* 更新表${table.name}信息
	*/
	@Override
	public int updateBySelective(${entity} ${table.entityPath}) {
		int rc =${table.entityPath}Mapper.updateBySelective(${table.entityPath});
		return rc;
    }
</#if>
</#list>

<#list table.fields as field>
<#if field.keyFlag>
	/**
	*  新增表${table.name}信息
	*/
	@Override
	public int insertBySelective(${entity} ${table.entityPath}) {
<#--		${table.entityPath}.setId(SnowflakeIdWorker.getId());-->
		int rc =${table.entityPath}Mapper.insertBySelective(${table.entityPath});
		return rc;
    }
</#if>
</#list>

<#list table.fields as field>
<#if field.keyFlag>
	/**
	*  ${table.name}分页查询
	*/
	@Override
	public  PageInfo<${entity}> getPage(${entity} ${table.entityPath}){
		Long total = ${table.entityPath}Mapper.selectCount(${table.entityPath});
		List<${entity}> list = ${table.entityPath}Mapper.selectList(${table.entityPath});
		PageInfo<${entity}> pageInfo = new PageInfo(${table.entityPath}.getPage(), ${table.entityPath}.getLimit(), total,list);
		return pageInfo;
	}
</#if>
</#list>

}
